﻿using System;

class Task3
{
    static void Main()
    {
        //Bulls and Cows

        int secretNumber = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());
        int c = int.Parse(Console.ReadLine());

        int firstNumber = secretNumber / 1000;
        int secondNumber = (secretNumber / 100) % 10;
        int thirdNumber = (secretNumber / 10) % 10;
        int fourthNumber = secretNumber % 10;

        int combinations = (int)Math.Pow(2, b); // -1        

        if (b == 4)
        {
            Console.WriteLine(secretNumber);
        }
        else if (b == 3 && c== 0)
        {
            for (int i = 1; i <= 9; i++)
            {
                Console.Write("{0}{1}{2}{3} ", i, firstNumber, secondNumber, thirdNumber);                
                Console.Write("{0}{1}{2}{3} ", firstNumber, i, thirdNumber, fourthNumber);
                Console.Write("{0}{1}{2}{3} ", firstNumber, secondNumber, i, fourthNumber);
                Console.Write("{0}{1}{2}{3} ", firstNumber, secondNumber, thirdNumber, i);
            }
        }
        else if (b == 3 && c == 1)
        {
            Console.WriteLine("No");
            //for (int i = 1; i <= 9; i++)
            //{
            //    Console.Write("{0}{1}{2}{3} ", i, firstNumber, secondNumber, thirdNumber);
            //    Console.Write("{0}{1}{2}{3} ", firstNumber, i, thirdNumber, fourthNumber);
            //    Console.Write("{0}{1}{2}{3} ", firstNumber, secondNumber, i, fourthNumber);
            //    Console.Write("{0}{1}{2}{3} ", firstNumber, secondNumber, thirdNumber, i);
            //}
        }
        else if (b == 2)
        {
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 1; j <= 9; j++)
                {
                    Console.Write("{0}{1}{2}{3} ", firstNumber, secondNumber, i, j);
                    Console.Write("{0}{1}{2}{3} ", firstNumber, i, secondNumber, j);
                    Console.Write("{0}{1}{2}{3} ", firstNumber, i, j, secondNumber);
                    Console.Write("{0}{1}{2}{3} ", i, firstNumber, secondNumber, j);
                    Console.Write("{0}{1}{2}{3} ", i, firstNumber, j, secondNumber);
                    Console.Write("{0}{1}{2}{3} ", i,j, firstNumber, secondNumber); 
                }
            }
        }
        
      
        if (secondNumber < firstNumber)
        {
            int temp = secondNumber;
            secondNumber = firstNumber;
            firstNumber = temp;
        }
        if (secondNumber > thirdNumber)
        {
            int temp = secondNumber;
            secondNumber = thirdNumber;
            thirdNumber = temp;
        }
        if (thirdNumber > fourthNumber)
        {
            int temp = thirdNumber;
            thirdNumber = fourthNumber;
            fourthNumber = temp;
        }

    }
}

